package com.emmy.walnut.custom;

import android.content.Context;
import android.widget.TextView;

import com.emmy.walnut.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

import java.text.DecimalFormat;

/**
 * @ClassName MyMarkerView
 * @Description TODO
 * @Author zhouxuan
 * @Date 2020/02/08 15:59
 * @Version 1.0
 */
public class MyMarkerView extends MarkerView {

    private final TextView tvContent;
    private final ValueFormatter yAxisValueFormatter;

    public MyMarkerView(Context context, ValueFormatter yAxisValueFormatter){
        super(context, R.layout.custom_marker_view);

        this.yAxisValueFormatter = yAxisValueFormatter;
        tvContent = findViewById(R.id.tvContent);
    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        tvContent.setText(String.format("%s", yAxisValueFormatter.getFormattedValue(e.getY())));

        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}
